package cn.edu.tsinghua.training.demo;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Service;

@Service
@Aspect
public class Log {

	
	@Before("execution(* *..Business.*(..))")
	public void before(JoinPoint joinpoint) {
		System.out.println("before "+ joinpoint.getSignature().getName() +"...");
	}
	
	@After("execution(* *..Business.*(..))")
	public void after(JoinPoint joinpoint) {
		System.out.println("after "+ joinpoint.getSignature().getName() +"...");
	}
	
	@Around("execution(* *..Business.*(..))")
	public void around(ProceedingJoinPoint proceedingJoinPoint) {
		System.out.println("arouond before "+ proceedingJoinPoint.getSignature().getName() +"...");
		try {
			proceedingJoinPoint.proceed();//
		} catch (Throwable e) {
			e.printStackTrace();
		}//save()
		System.out.println("arouond after "+ proceedingJoinPoint.getSignature().getName() +"...");
	}
	
}
